package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.AttributeTemplateAddNewDTO;
import cn.tedu.store.commons.pojo.product.dto.AttributeTemplateUpdateDTO;
import cn.tedu.store.commons.pojo.product.vo.AttributeTemplateListItemVO;
import cn.tedu.store.commons.pojo.product.vo.AttributeTemplateStandardVO;
import cn.tedu.store.product.service.IAttributeTemplateService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "04.属性模板模块")
@Validated
@RestController
@RequestMapping("/attribute-templates")
public class AttributeTemplateController {

    @Autowired
    private IAttributeTemplateService attributeTemplateService;

    @ApiOperation("添加属性模板")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated AttributeTemplateAddNewDTO attributeTemplateAddNewDTO){
        log.debug("开始处理[添加属性模板]请求 参数:{}",attributeTemplateAddNewDTO);
        attributeTemplateService.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除属性模板")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id",value = "模板id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理[删除属性模板]请求 参数:{}", id);
        attributeTemplateService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改属性模板")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id",value = "模板id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, AttributeTemplateUpdateDTO attributeTemplateUpdateDTO){
        log.debug("开始处理[修改属性模板]请求 参数:{},{}",id,attributeTemplateUpdateDTO);
        attributeTemplateService.updateById(id,attributeTemplateUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("获取属性模板详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id",value = "模板id",required = true,dataType = "long")
    @GetMapping("/{id:[0-9]+}/get-by-id")
    public JsonResult<AttributeTemplateStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理[获取属性模板详情]请求 参数:{}",id);
        return JsonResult.ok(attributeTemplateService.getStandardById(id));
    }

    @ApiOperation("获取属性模板列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<AttributeTemplateListItemVO>> list(){
        log.debug("开始处理[获取属性模板列表]请求 参数:无");
        return JsonResult.ok(attributeTemplateService.list());
    }

}
